<template>
	<view>
		<view v-if="type==1" class="succeedbg">
			<!-- <view class="amount">￥<view class="amount">{{data.order_amount}}</view></view> -->
			<view>￥<text class="amount">{{data.amount}}</text></view>
		</view>
		<view class="" style="text-align: start;">
			<view class="time">当前等级：{{data.level_name}}</view>
			<view class="time">当前到期时间：{{data.expire_time}}</view> 
		</view>
		<view v-if="type!=1" style="height: 340rpx;">
		</view>
		<view v-if="data.is_show==1" class="submit-s" @tap="getpay">立即续签</view>
	</view>
</template>

<script>
	import {scancode,expire,Upexpire} from '@/api/user';
	import {prepay} from '@/api/app'
	import { wxpay, alipay } from '@/utils/pay'
	import {
		strToParams,
		arraySlice,
		getRect,
		getcu
	} from '@/utils/tools'
	export default {
		data() {
			return {
				codeid:'',
				pay_status:'',
				id:'',
				type:'',
				data:[],
			}
		},
		onLoad() {
			// const options = this.$Route.query;
			// if (options && options.scene) {
			// 	const scene = strToParams(decodeURIComponent(options.scene));
			// 	this.codeid = scene.code_id;
			// }
			// this.getscancode()
			this.getexpire()
		}, 
		methods: {
			getpay(){
				if(this.type==1){
					prepay({
						from: 'renew',
						// order_id: this.id,
						pay_way: 1,
					}).then(({ code, data }) => {
						switch(code) {
							case 1: 
								this.handleWechatPay(data); 
								break;
							case 10001: 
								this.handleAlipayPay(data); 
								break;
							case 20001: 
								this.handleWalletPay(); 
								break;
						}
					}).catch(err => {
						
					}).finally(() => {
						setTimeout(() => {
							this.loadingPay = false
						}, 500)
					})
				}else{
					this.getupexpire()
				}
			},
			async getupexpire(){
				const {
					code,
					msg,
					data,
				} = await Upexpire({})
				if (code == 1) {
					this.apifun.toast(msg)
					this.getexpire()
				}
			},
			async getexpire(){
				const {
					code,
					msg,
					data,
				} = await expire({})
				if (code == 1) {
					this.data = data
					this.pay_status = data.pay_status
					this.id = data.id
					this.type = data.type
				}
			},
			async getexpire(){
				const {
					code,
					msg,
					data,
				} = await expire({})
				if (code == 1) {
					this.data = data
					this.pay_status = data.pay_status
					this.id = data.id
					this.type = data.type
				}
			},
			// async getscancode(){
			// 	const {
			// 		code,
			// 		msg,
			// 		data,
			// 	} = await scancode({code_id:this.codeid})
			// 	if (code == 1) {
			// 		this.data = data
			// 		this.pay_status = data.pay_status
			// 		this.id = data.id
			// 	}
			// },
			// 微信支付
			handleWechatPay(data) {
				wxpay(data).then(res => {
					console.log(res)
					this.getexpire()
					// this.handPayResult(res)
				}).catch(err => {
					console.log(err)
				})
			},
			// 支付后处理
			handPayResult(result) {
				this.$Router.replace({
					path: '/pages/mine/index',
				})
			},
		}
	}
</script>

<style>
page{
		
	}
.succeedbg{
	text-align: center;
	width: 100%;
	height: 340rpx;
	background: linear-gradient(270deg, #bb012a 0%, #f5335e 100%);
	color: #fff;
	padding-top: 140rpx;
}
.amount{
	font-size: 48rpx;
}
.time{
	margin-bottom: 10rpx;
	font-size: 28rpx;
	padding: 16rpx 26rpx;
	background-color: #fff;
}
.submit-s{
	font-size: 30rpx;
	padding: 18rpx;
	background: linear-gradient(270deg, #bb012a 0%, #f5335e 100%);
	border-radius: 50rpx;
	margin-top: 630rpx;
}
</style>
